package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.CangkuKuCunMapper;
import com.zhongyu.mapper.KuCunBdMapper;
import com.zhongyu.pojo.Goods;
import com.zhongyu.pojo.KucunBiandong;
import com.zhongyu.service.KuCunBdService;
import com.zhongyu.vo.KuCunBdVo;
import com.zhongyu.vo.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service("KuCunBdService")
public class KuCunBdServicelmpl extends ServiceImpl<KuCunBdMapper, KucunBiandong> implements KuCunBdService {
   @Resource
   private  KuCunBdMapper kuCunBdMapper;
    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, KuCunBdVo kuCunBdVo) {
        LambdaQueryWrapper<KucunBiandong> wrapper= Wrappers.<KucunBiandong>lambdaQuery();
        wrapper.eq(kuCunBdVo.getUserId()!=null,KucunBiandong::getUserid,kuCunBdVo.getUserId())
                .ge(kuCunBdVo.getStartDate()!=null,KucunBiandong::getOpertime,kuCunBdVo.getStartDate())
                .le(kuCunBdVo.getEndDate()!=null,KucunBiandong::getOpertime,kuCunBdVo.getEndDate())
                .eq(kuCunBdVo.getCangkuId()!=null,KucunBiandong::getCangkuId,kuCunBdVo.getCangkuId())
                .eq(kuCunBdVo.getGoodsId()!=null,KucunBiandong::getGoodsId,kuCunBdVo.getGoodsId())
                .eq(kuCunBdVo.getType()!=null,KucunBiandong::getType,kuCunBdVo.getType());
        Page page=new Page(pageNo,pageSize);
        List<KucunBiandong> list=baseMapper.findAll(page,wrapper);
        return new PageResult(list,page.getTotal());
    }

    @Override
    public List<KucunBiandong> searchAll() {
        return kuCunBdMapper.selectList(null);
    }

    @Override
    public List<KucunBiandong> searchById(Integer cangkuId,Integer goodsId) {
        return kuCunBdMapper.findById(cangkuId,goodsId);
    }

    @Override
    public void add(KucunBiandong cangkuBiandong) {
kuCunBdMapper.insert(cangkuBiandong);
    }

    @Override
    public void del(Integer id) {
kuCunBdMapper.deleteById(id);
    }

    @Override
    public void update(KucunBiandong cangkuBiandong) {
kuCunBdMapper.updateById(cangkuBiandong);
    }
}
